public function validateWeight(Package $package)
 {
     $math = $this->getMath();
     $converter = $this->getWeightConverter();
     $country = $this->getImportCountry($package->getRecipientAddress()->getCountryCode());
     $countryMaxWeight = $converter->convert($country->getMaximumWeight(), $this->get('mass_unit'), $package->getWeight()->getUnit());
     if ($math->greaterThan($package->getWeight()->getValue(), $countryMaxWeight)) {
         throw new ViolationException('Sender country weight limit is exceeded.');
     }
 }
 public function getPrice(Package $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 ViolationException('Can not calculate shipping for this weight.');
     }
     return $price;
 }