public UpsValidatonResponse ValidateAddress(Address address)
        {
            var client = CreateAddressValidatorClinet();
            var status = true;
            var message = "Valid Address";
            AddressIndicator addressIndicator = AddressIndicator.ValidAddressIndicator;
            IEnumerable<Address> addresses = null;

            try
            {
                var request = Create(address);
                var response = client.ProcessXAV(request.UPSSecurity, request.XAVRequest);

                if (response != null)
                {

                    switch (response.ItemElementName)
                    {
                        case ItemChoiceType.AmbiguousAddressIndicator:
                            status = false;
                            message = "Ambiguous Address found";
                            addresses = Parse(response.Candidate);
                            addressIndicator = AddressIndicator.AmbiguousAddressIndicator;
                            break;
                        case ItemChoiceType.ValidAddressIndicator:
                            addresses = Parse(response.Candidate);
                            break;
                        case ItemChoiceType.NoCandidatesIndicator:
                        default:
                            status = false;
                            message = "No Address Found";
                            addressIndicator = AddressIndicator.NoCandidatesIndicator;
                            break;
                    }
                }
            }
            catch (CommunicationException e)
            {

                client.Abort();
                return Parse(e);
            }
            catch (TimeoutException e)
            {
                client.Abort();
                return Parse(e);
            }
            catch (Exception ex)
            {
                client.Abort();
                return Parse(ex);
            }
            return new UpsValidatonResponse()
            {
                Status = status,
                Message = message,
                Addresses = addresses,
                AddressIndicator = addressIndicator
            };
        }
        public UpsValidatonResponse ValidateAddress(Address address)
        {
            var response = _streetValidator.ValidateAddress(address);

            if (response != null && response.AddressIndicator == AddressIndicator.ValidAddressIndicator && response.Addresses != null)
            {
                var validatedAddress = response.Addresses.FirstOrDefault();
                if (
                                   !string.Equals(validatedAddress.State, address.State,
                                       StringComparison.InvariantCultureIgnoreCase))
                {
                    response.Status = false;
                    response.Message = "State is invalid";
                    response.AddressIndicator = AddressIndicator.NoCandidatesIndicator;
                }
                else if (
                    !string.Equals(validatedAddress.Zip, address.Zip,
                        StringComparison.InvariantCultureIgnoreCase))
                {
                    response.Status = false;
                    response.Message = "State is invalid";
                    response.AddressIndicator = AddressIndicator.NoCandidatesIndicator;
                }
                else if (!string.Equals(validatedAddress.City, address.City, StringComparison.InvariantCultureIgnoreCase))
                {
                    //Resolve city 
                    var cityValidatorResponse = _cityValidator.ValidateCityStreetZip(address.City, address.State, address.Zip);

                    if (cityValidatorResponse.Status)
                    {

                        var resolvedCities = cityValidatorResponse.Addresses.Select(a => a.City).ToList<string>();
                        if (string.IsNullOrEmpty(
                           resolvedCities.FirstOrDefault(
                                rc => rc.ToString().Equals(address.City, StringComparison.InvariantCultureIgnoreCase))))
                        {
                            response.Status = false;
                            response.Message = "City is invalid";
                            response.AddressIndicator = AddressIndicator.NoCandidatesIndicator;
                        }
                    }
                    else
                    {
                        response.AddressIndicator = AddressIndicator.NoCandidatesIndicator;
                        response.Message = cityValidatorResponse.Message;
                        response.Status = false;
                    }
                }
            }

            return response;
        }
 public UpsValidatonResponse ValidateStreetUPSAPI(Address address)
 {
     return _streetValidator.ValidateAddress(address);
 }
        private XAVRequest1 Create(Address address)
        {
            var request = new XAVRequest1()
            {
                UPSSecurity = new UPSSecurity()
                {
                    ServiceAccessToken = new UPSSecurityServiceAccessToken()
                    {
                        AccessLicenseNumber = _config.AccessLicenseNumber
                    },
                    UsernameToken = new UPSSecurityUsernameToken()
                    {
                        Username = _config.UserName,
                        Password = _config.Password
                    }
                },
                XAVRequest = new XAVRequest()
                {
                    Request = new RequestType()
                    {
                        RequestOption = new[] { "1" }
                    },
                    AddressKeyFormat = new AddressKeyFormatType()
                    {
                        AddressLine = address.AddressLine.ToArray(),
                        PoliticalDivision2 = address.City,
                        PoliticalDivision1 = address.State,
                        PostcodePrimaryLow = address.Zip,
                        PostcodeExtendedLow = address.ZipPlusFour,
                        CountryCode = _config.CountryCode
                    }
                }
            };

            return request;
        }