Exemple #1
0
        public async Task USPS_Domestic_Saturday_Delivery()
        {
            var rateManager = new RateManager();

            rateManager.AddProvider(new USPSProvider(_uspsUserId));

            var today        = DateTime.Now;
            var nextFriday   = today.AddDays(12 - (int)today.DayOfWeek).Date + new TimeSpan(10, 0, 0);
            var nextThursday = nextFriday.AddDays(-1);

            var origin      = new Address("", "", "06405", "US");
            var destination = new Address("", "", "20852", "US");

            var response = await rateManager.GetRatesAsync(origin, destination, Package1, new ShipmentOptions()
            {
                ShippingDate     = nextFriday,
                SaturdayDelivery = true
            });

            Assert.NotNull(response);
            Assert.IsNotEmpty(response.Rates);

            // Sometimes only Priority Mail Express 2-Day works and we have to try it on Thursday
            if (!response.Rates.Any(r => r.Options.SaturdayDelivery))
            {
                response = await rateManager.GetRatesAsync(origin, destination, Package1, new ShipmentOptions()
                {
                    ShippingDate     = nextThursday,
                    SaturdayDelivery = true
                });

                Assert.NotNull(response);
                Assert.IsNotEmpty(response.Rates);
            }

            Debug.WriteLine(string.Format("Rates returned: {0}", response.Rates.Any() ? response.Rates.Count.ToString() : "0"));

            Assert.IsEmpty(response.Errors);
            Assert.True(response.Rates.Any(r => r.Options.SaturdayDelivery));

            foreach (var rate in response.Rates)
            {
                Assert.NotNull(rate);
                Assert.True(rate.TotalCharges > 0);

                Debug.WriteLine(rate.Name + ": " + rate.TotalCharges);
            }
        }
Exemple #2
0
        public async Task UPSSaturdayDelivery()
        {
            var from    = new Address("Annapolis", "MD", "21401", "US");
            var to      = new Address("Fitchburg", "WI", "53711", "US");
            var package = new Package(7, 7, 7, 6, 0);

            var today      = DateTime.Now;
            var nextFriday = today.AddDays(12 - (int)today.DayOfWeek);

            var rateManager = new RateManager();

            rateManager.AddProvider(new UPSProvider(UPSLicenseNumber, UPSUserId, UPSPassword));

            var r = await rateManager.GetRatesAsync(from, to, package, new ShipmentOptions()
            {
                ShippingDate     = nextFriday,
                SaturdayDelivery = true
            });

            var fedExRates = r.Rates.ToList();

            Assert.NotNull(r);
            Assert.True(fedExRates.Any());
            Assert.True(fedExRates.Any(r => r.Options.SaturdayDelivery));
        }
Exemple #3
0
        public async Task USPSCurrency()
        {
            var rateManager = new RateManager();

            rateManager.AddProvider(new USPSInternationalProvider(_uspsUserId));

            var response = await rateManager.GetRatesAsync(_domesticAddress1, _internationalAddress2, _package1);

            var rates = response.Rates;

            Assert.NotNull(response);
            Assert.True(rates.Any());
            Assert.False(rates.Any(r => r.CurrencyCode != "USD"));
        }
Exemple #4
0
        public async Task UPSCurrency()
        {
            var from    = new Address("Amsterdam", "", "1043 AG", "NL");
            var to      = new Address("London", "", "SW1A 2AA", "GB");
            var package = new Package(1, 1, 1, 5, 1);

            var rateManager = new RateManager();

            rateManager.AddProvider(new UPSProvider(UPSLicenseNumber, UPSUserId, UPSPassword));
            var r = await rateManager.GetRatesAsync(from, to, package);

            var fedExRates = r.Rates.ToList();

            Assert.NotNull(r);
            Assert.True(fedExRates.Any());
            Assert.False(fedExRates.Any(r => r.CurrencyCode != "EUR"));
        }
Exemple #5
0
        static async Task Main()
        {
            var appSettings = ConfigurationManager.AppSettings;

            // You will need a license #, userid and password to utilize the UPS provider.
            var upsLicenseNumber = appSettings["UPSLicenseNumber"];
            var upsUserId        = appSettings["UPSUserId"];
            var upsPassword      = appSettings["UPSPassword"];

            // You will need an account # and meter # to utilize the FedEx provider.
            var fedexKey           = appSettings["FedExKey"];
            var fedexPassword      = appSettings["FedExPassword"];
            var fedexAccountNumber = appSettings["FedExAccountNumber"];
            var fedexMeterNumber   = appSettings["FedExMeterNumber"];
            var fedexHubId         = appSettings["FedExHubId"]; // 5531 is the hubId to use in FedEx's test environment
            var fedexUseProduction = Convert.ToBoolean(appSettings["FedExUseProduction"]);

            // You will need a userId to use the USPS provider. Your account will also need access to the production servers.
            var uspsUserId = appSettings["USPSUserId"];

            // You will need a Site ID and Password to use DHL provider.
            var dhlSiteId   = appSettings["DHLSiteId"];
            var dhlPassword = appSettings["DHLPassword"];

            // Setup package and destination/origin addresses
            var packages = new List <Package>
            {
                new Package(12, 12, 12, 35, 150),
                new Package(4, 4, 6, 15, 250)
            };

            var origin      = new Address("", "", "06405", "US");
            var destination = new Address("", "", "20852", "US"); // US Address
            //var origin = new Address("Amsterdam", "", "1043 AG", "NL"); // Netherlands Address
            //var destination  = new Address("London", "", "SW1A 2AA", "GB"); // Great Britain Address
            //var destination = new Address("", "", "88888", "US"); // Wrong US Address
            //var destination = new Address("Domont", "", "95330", "FR"); // France Address
            //var destination = new Address("", "", "00907", "PR"); // Puerto Rico Address
            //var destination = new Address("", "", "L4W 1S2", "CA"); // Canada Address
            //var destination = new Address("", "", "SW1E 5JL", "GB"); // UK Address
            //var destination = new Address("", "", "1042 AG", "NL");   // Netherlands Address

            // Create RateManager
            var rateManager = new RateManager();

            // Add desired DotNetShippingProviders
            rateManager.AddProvider(new UPSProvider(upsLicenseNumber, upsUserId, upsPassword)
            {
                UseProduction = false
            });
            rateManager.AddProvider(new FedExProvider(fedexKey, fedexPassword, fedexAccountNumber, fedexMeterNumber, fedexUseProduction));
            rateManager.AddProvider(new FedExSmartPostProvider(fedexKey, fedexPassword, fedexAccountNumber, fedexMeterNumber, fedexHubId, fedexUseProduction));
            rateManager.AddProvider(new USPSProvider(uspsUserId));
            rateManager.AddProvider(new USPSInternationalProvider(uspsUserId));

            var dhlConfiguration = new DHLProviderConfiguration(dhlSiteId, dhlPassword, useProduction: false)
                                   .ExcludeServices(new char[] { 'C' });

            rateManager.AddProvider(new DHLProvider(dhlConfiguration));

            // (Optional) Add RateAdjusters
            rateManager.AddRateAdjuster(new PercentageRateAdjuster(.9M));

            // Call GetRates()
            var shipment = await rateManager.GetRatesAsync(origin, destination, packages,
                                                           new ShipmentOptions()
            {
                SaturdayDelivery = true
            });

            // Iterate through the rates returned
            foreach (var rate in shipment.Rates)
            {
                Console.WriteLine(rate);
            }

            // Iterate through the errors returned
            if (shipment.Errors.Count > 0)
            {
                Console.WriteLine("Errors:");
                foreach (var error in shipment.Errors)
                {
                    Console.WriteLine(error.Number);
                    Console.WriteLine(error.Source);
                    Console.WriteLine(error.Description);
                }
            }

            // Iterate through the internal errors
            if (shipment.InternalErrors.Count > 0)
            {
                Console.WriteLine("Internal Errors:");
                foreach (var error in shipment.InternalErrors)
                {
                    Console.WriteLine(error);
                }
            }

            Console.WriteLine("Done!");
        }