/**
  * Create a new rate
  *
  * @param MatheusGontijo_EasyShippingRules_Model_Custommethod $method
  * @param MatheusGontijo_EasyShippingRules_Model_Rule         $rule
  *
  * @return Mage_Shipping_Model_Rate_Result_Method
  */
 public function createRate(MatheusGontijo_EasyShippingRules_Model_Custommethod $method, MatheusGontijo_EasyShippingRules_Model_Rule $rule)
 {
     /** @var Mage_Shipping_Model_Rate_Result_Method $rate */
     $rate = Mage::getModel('shipping/rate_result_method');
     $rate->setCarrier(MatheusGontijo_EasyShippingRules_Model_Shipping_Carrier::EASY_SHIPPING_RULES_CODE . '_' . $method->getEasyshippingrulesCarrierId());
     $rate->setCarrierTitle($method->getCarrierName());
     $rate->setMethod(MatheusGontijo_EasyShippingRules_Model_Shipping_Carrier::EASY_SHIPPING_RULES_CODE . '_' . $method->getId() . '_' . $rule->getId());
     $rate->setMethodTitle($method->getName());
     $price = 0;
     if ($method->getPricePercentage()) {
         $price = $method->getPricePercentage();
     } else {
         /**
          * it makes no sense apply all price conditions
          * because each iteration will replace last one.
          * In this case admin user should setting price in method, not in rules
          */
         foreach ($method->getRules() as $rule) {
             $price = $rule->getPricePercentage();
             break;
         }
     }
     if ($method->getPriceAction() == MatheusGontijo_EasyShippingRules_Helper_Data::FIXED_PER_ITEM_QTY_PRICE_ACTION) {
         $price = Mage::getSingleton('checkout/cart')->getQuote()->getItemsQty() * $price;
     } elseif ($method->getPriceAction() == MatheusGontijo_EasyShippingRules_Helper_Data::SUBTOTAL_PERCENTAGE_PRICE_ACTION) {
         $price = $this->_getSubtotal() * ($price / 100);
     }
     $rate->setPrice($price);
     return $rate;
 }
 /**
  * Add custom method filter
  *
  * @param MatheusGontijo_EasyShippingRules_Model_Custommethod $method
  *
  * @return MatheusGontijo_EasyShippingRules_Model_Resource_Rule_Collection
  */
 public function addCustomMethodFilter(MatheusGontijo_EasyShippingRules_Model_Custommethod $method)
 {
     $read = $this->getResource()->getReadConnection();
     $this->getSelect()->join(array('custommethod_rule' => $this->getTable('easyshippingrules/custom_method_rule')), $read->quoteInto('main_table.easyshippingrules_rule_id = custommethod_rule.easyshippingrules_rule_id ' . 'AND custommethod_rule.easyshippingrules_custom_method_id = ?', $method->getId()), array());
     return $this;
 }