/**
  * @param PackageInterface $package
  * @return ZoneCalculator
  */
 public function getZoneCalculator($package)
 {
     $country = $this->getImportCountry($package->getRecipientAddress()->getCountryCode());
     $calculators = $this->get('zone_calculators');
     if (!array_key_exists($country->getZone(), $calculators)) {
         throw new InvalidConfigurationException('Price group does not exist.');
     }
     return $calculators[$country->getZone()];
 }
 public function getPrice(PackageInterface $package)
 {
     $weight = $package->getWeight();
     $volumetricWeight = $this->getVolumetricWeightCalculator()->calculate($package->getDimensions());
     $weight = $this->getWeightConverter()->convert($weight->getValue(), $weight->getUnit(), $this->get('mass_unit'));
     $volumetricWeight = $this->getWeightConverter()->convert($volumetricWeight->getValue(), $volumetricWeight->getUnit(), $this->get('mass_unit'));
     $math = $this->getMath();
     if ($math->greaterThan($volumetricWeight, $weight)) {
         $weight = $volumetricWeight;
     }
     $importCountry = $this->detectImportCountry($package->getRecipientAddress());
     $zone = $this->get('zones')[$importCountry->getZone()];
     $currentWeight = null;
     $price = null;
     foreach ($zone['weight_prices'] as $w => $p) {
         if ($math->lessOrEqualThan($weight, $w) && $math->greaterThan($weight, $currentWeight)) {
             $currentWeight = $w;
             $price = $p;
         }
     }
     if (is_null($price)) {
         throw new InvalidWeightException('Can not calculate shipping for this weight.');
     }
     return $price;
 }