You could test the cart for the products_id to get the quantity in the cart:
$_SESSION['cart']->in_cart_check('product_id','12')
Example: in the USPS shipping module to add 7.50 for each Product that is products_id 12 in the cart:
/includes/modules/shipping/usps.php
you can use:
$cost = preg_replace('/[^0-9.]/', '', $cost);
// bof: add additional 7.50 for each products_id 12 in the cart
global $cart;
$chk_cart_products_id_12 = $_SESSION['cart']->in_cart_check('products_id','12');
$additional_charge = $chk_cart_products_id_12 * 7.50;
$methods[] = array('id' => $type,
'title' => $title,
'cost' => ($cost * $shipping_num_boxes) + $additional_charge + (MODULE_SHIPPING_USPS_HANDLING_METHOD == 'Box' ? MODULE_SHIPPING_USPS_HANDLING * $shipping_num_boxes : MODULE_SHIPPING_USPS_HANDLING) );
// eof: add additional 7.50 for each products_id 12 in the cart