private ShippingResult UPSTrackingResultWrap(UPSTrackingResult.TrackResponse resultingMessage)
        {
            ShippingResult shippingResult = new ShippingResult();

            UPSTrackingResult.TrackResponseResponse response = (UPSTrackingResult.TrackResponseResponse)resultingMessage.Items[0];
            if (response.ResponseStatusCode == "1")
            {
                UPSTrackingResult.TrackResponseShipment shipment = (UPSTrackingResult.TrackResponseShipment)resultingMessage.Items[1];
                shippingResult.ServiceType = shipment.Service[0].Description;
                shippingResult.StatusCode  = shipment.Package[0].Activity[0].Status[0].StatusType[0].Code;
                shippingResult.Status      = shipment.Package[0].Activity[0].Status[0].StatusType[0].Description;

                if (!string.IsNullOrEmpty(shippingResult.StatusCode))
                {
                    if (shippingResult.StatusCode == "D")
                    {
                        shippingResult.Delivered         = true;
                        shippingResult.StatusSummary     = shipment.Package[0].Activity[0].ActivityLocation[0].Description;
                        shippingResult.DeliveredDateTime = shipment.Package[0].Activity[0].Date + " " + shipment.Package[0].Activity[0].Time;
                        shippingResult.SignatureName     = string.IsNullOrEmpty(shipment.Package[0].Activity[0].ActivityLocation[0].SignedForByName) ? "" : shipment.Package[0].Activity[0].ActivityLocation[0].SignedForByName;
                    }
                }


                if (!string.IsNullOrEmpty(shippingResult.StatusCode))
                {
                    if (shippingResult.StatusCode != "D")
                    {
                        shippingResult.PickupDate            = shipment.PickupDate;
                        shippingResult.ScheduledDeliveryDate = shipment.ScheduledDeliveryDate;

                        if (shipment.Package[0].Message != null)
                        {
                            shippingResult.Message = shipment.Package[0].Message[0].Description;
                        }
                    }
                }
            }
            else
            {
                shippingResult.StatusCode = "Error";
                shippingResult.Status     = response.Error.ErrorDescription;
                shippingResult.Message    = response.Error.ErrorDescription;
            }

            return(shippingResult);
        }
Exemple #2
0
        public ShippingResult GetTrackingResult()
        {
            ShippingResult shippingResult         = new ShippingResult();
            string         shippingResultInString = GetTrackingInfoUPSInString();
            XmlSerializer  serializer             = new XmlSerializer(typeof(UPSTrackingResult.TrackResponse));
            MemoryStream   memStream = new MemoryStream(Encoding.UTF8.GetBytes(shippingResultInString));

            UPSTrackingResult.TrackResponse resultingMessage = new UPSTrackingResult.TrackResponse();

            if (memStream != null)
            {
                resultingMessage = (UPSTrackingResult.TrackResponse)serializer.Deserialize(memStream);
            }

            shippingResult = UPSTrackingResultWrap(resultingMessage);

            return(shippingResult);
        }
        public List <ShippingResult> GetTrackingResult(List <string> trackingNumbers)
        {
            List <ShippingResult> shippingResult = new List <ShippingResult>();

            foreach (string trackingNumber in trackingNumbers)
            {
                string        shippingResultInString = GetTrackingInfoUPSInString(trackingNumber);
                XmlSerializer serializer             = new XmlSerializer(typeof(UPSTrackingResult.TrackResponse));
                _memStream = new MemoryStream(Encoding.UTF8.GetBytes(shippingResultInString));

                UPSTrackingResult.TrackResponse resultingMessage = new UPSTrackingResult.TrackResponse();

                if (_memStream != null)
                {
                    resultingMessage = (UPSTrackingResult.TrackResponse)serializer.Deserialize(_memStream);
                }

                shippingResult.Add(UPSTrackingResultWrap(resultingMessage));
            }

            return(shippingResult);
        }