Yes, this needs to be done in eCart.
first, you need to edit the cart object, add a new column for productCategory.
In another thread, you are working on limiting the quantity by category, you have created a recordset to return the product category, in the add to cart button, bind the new productCategory column to the category name from that recordset.
now create a new shipping rule for each category:
triggers:
number of items with a specific column value:
If the number of items where 'productCategory' has a value of 'Small' is '>' a value of '0'
calculation:
Based on items with a specific value:
total of 'Quantity' where 'productCategory has a value of 'Small' 'times' '4'
create the rules for large and medium as well.