def calculate_shipping_package
      
      store_config = invoice.site.store_config            
      if !store_config.auto_calculate_packages                        
        return self.custom_shipping_package(store_config, self)        
      end
      
      variants = self.line_items.sort_by{ |li| li.quantity * (li.variant.volume ? li.variant.volume : 0.00) * -1 }.collect{ |li| li.variant.downloadable ? nil : li.variant }.reject{ |v| v.nil? }      
      ShippingPackage.where(:site_id => self.invoice.site_id).reorder(:flat_rate_price).all.each do |sp|
        if sp.fits(variants)
          self.shipping_package_id = sp.id
          self.save
          return true          
        end 
      end                    
      Caboose.log("Error: line item #{li.id} (#{li.variant.product.title}) does not fit into any package.")
      return false
    end
def calculate_shipping_package
      
      store_config = invoice.site.store_config            
      if !store_config.auto_calculate_packages                        
        return self.custom_shipping_package(store_config, self)        
      end
      
      variants = self.line_items.sort_by{ |li| li.quantity * (li.variant.volume ? li.variant.volume : 0.00) * -1 }.collect{ |li| li.variant.downloadable ? nil : li.variant }.reject{ |v| v.nil? }      
      ShippingPackage.where(:site_id => self.invoice.site_id).reorder(:flat_rate_price).all.each do |sp|
        if sp.fits(variants)
          self.shipping_package_id = sp.id
          self.save
          return true          
        end 
      end                    
      Caboose.log("Error: line item #{li.id} (#{li.variant.product.title}) does not fit into any package.")
      return false
    end
Calculates the shipping packages required for all the items in the invoice