Let's say you want to check the cart for how many Guns (categories_id 2) and Rifles (categories_id 3) there are ... and that the Products in those Categories have the master_categories_id set to those categories_id ...
Code:
global $cart;
$chk_guns = $_SESSION['cart']->in_cart_check('master_categories_id','2');
$chk_rifles = $_SESSION['cart']->in_cart_check('master_categories_id','3');
$extra_handling_fee = ($chk_guns * 50) + ($chk_rifles * 35);
Now, the $extra_handling_fee can be added to the cost for the quotes ...