You can count how many products are in the shopping cart based on their master_categories_id with, for example to know how many Products are from categories_id 12 and categories_id 15 where this is used as the master_categories_id value of 12 and 15:
Code:
global $cart;
$chk_cat12 = $_SESSION['cart']->in_cart_check('master_categories_id','12');
$chk_cat15 = $_SESSION['cart']->in_cart_check('master_categories_id','15');
You can call the variables anything you want, I just use $chk_cat12 and $chk_cat15 as they make sense ...
From these values, you can then build a shipping cost ...