The basic principle, certainly. But the queue is not part of the storage system, so you need to query for available items in a different way.
The attached model demonstrates a general approach that would also work for the rack, if you want to unify the logic.
The queue pushes all entering items to a global list in the "Send to Port" option. The list has a "Type" field that mirrors the value of the Type label and is partitioned by the object that pushed the item to the list (so you only need a single list for multiple objects).

The OnMessage code then pulls items with matching type from the correct partition, up to the specified quantity. If there are not enough items on the list to reach the quantity, the rest is ignored.
Object current = ownerobject(c);
Object fromObject = param(1);
Variant msgparam1 = param(2);
Variant msgparam2 = param(3);
Variant msgparam3 = param(4);
int type = msgparam1;
int qty = msgparam2;
// Pull matching items from list
string pullQuery = "WHERE Type == " + string.fromNum(type, 0);
Variant pulledItems = List("ItemList").pull(pullQuery, qty, 0, current, current);
// Release pulled items
for(int i = 1; i <= pulledItems.length; i++)
{
releaseitem(pulledItems, 1);
}
timed-release-fm_1.fsm