public ShippingDetailInfo Execute(ShippingDetailInfo input)
        {
            IZoneDifferenceStrategy zoneDiffDecor = ZoneDifferenceStrategyFactory.GetInstance().GetZoneDifferenceDecoratorInstance(input.DeliveryMethod);
            int zoneDifference = zoneDiffDecor.Difference(input.OriginAddress.PostalCode, input.DestinationAddress.PostalCode);

            switch (input.DeliveryMethod)
            {
            case DeliveryMethodEnum.Air:
                input.Cost = zoneDifference * OunceToPound(Convert.ToDouble(input.PackageInfo.Weight)) * GetPackageVolume(input.PackageInfo);
                break;

            case DeliveryMethodEnum.Rail:
            case DeliveryMethodEnum.Ground:
                input.Cost = zoneDifference * OunceToPound(Convert.ToDouble(input.PackageInfo.Weight));
                break;

            default:
                throw new InvalidOperationException();
            }

            // Insurance Calculation
            if (input.IsInsured)
            {
                input.Cost *= 1.02;
            }

            return(input);
        }
Пример #2
0
 // Singleton implementation to get instance of the WeightAdatperInstance.
 public static ZoneDifferenceStrategyFactory GetInstance()
 {
     if (instance == null)
     {
         instance = new ZoneDifferenceStrategyFactory();
     }
     return(instance);
 }
        public ShippingDetailInfo Execute(ShippingDetailInfo input)
        {
            IZoneDifferenceStrategy zoneDiffDecorator;

            if (input.DeliveryMethod == DeliveryMethodEnum.Rail)
            {
                zoneDiffDecorator = ZoneDifferenceStrategyFactory.GetInstance().GetZoneDifferenceDecoratorInstance(input.DeliveryMethod);
            }
            else
            {
                zoneDiffDecorator = ZoneDifferenceStrategyFactory.GetInstance().GetZoneDifferenceDecoratorInstance(input.DeliveryMethod);
            }

            input.DeliveryTime = ZoneFactorDict[input.DeliveryMethod] * zoneDiffDecorator.Difference(input.OriginAddress.PostalCode, input.DestinationAddress.PostalCode);
            return(input);        // zonefactory[key] ==> value    Air==>0.25
        }