All Downloads are FREE. Search and download functionalities are using the official Maven repository.

examples.InternationalAutocompleteExample Maven / Gradle / Ivy

There is a newer version: 3.18.3
Show newest version
package examples;

import com.smartystreets.api.ClientBuilder;
import com.smartystreets.api.SharedCredentials;
import com.smartystreets.api.exceptions.SmartyException;
import com.smartystreets.api.international_autocomplete.Client;
import com.smartystreets.api.international_autocomplete.Lookup;
import com.smartystreets.api.international_autocomplete.Candidate;

import java.io.IOException;
import java.util.ArrayList;

public class InternationalAutocompleteExample {
    public static void main(String[] args) throws IOException, SmartyException {
        // We recommend storing your authentication credentials in environment variables.
        SharedCredentials credentials = new SharedCredentials(System.getenv("SMARTY_AUTH_WEB"), System.getenv("SMARTY_AUTH_REFERER"));

        //            The appropriate license values to be used for your subscriptions
        //            can be found on the Subscriptions page of the account dashboard.
        //            https://www.smartystreets.com/docs/cloud/licensing
        ArrayList licenses = new ArrayList();
        licenses.add("international-autocomplete-cloud");
        Client client = new ClientBuilder(credentials).withLicenses(licenses).buildInternationalAutcompleteApiClient();
        Lookup lookup = new Lookup("Louis");

        // Documentation for input fields can be found at:
        // https://smartystreets.com/docs/cloud/international-address-autocomplete-api#pro-http-request-url


        lookup.setCountry("FRA");
        lookup.setLocality("Paris");

        client.send(lookup);

        System.out.println("*** Result ***");
        System.out.println();
        printResult(lookup);
    }

    private static void printResult(Lookup lookup) {
        for (Candidate candidate : lookup.getResult()) {
            System.out.print(candidate.getStreet());
            System.out.print(" ");
            System.out.print(candidate.getLocality());
            System.out.print(" ");
            System.out.print(candidate.getAdministrativeArea());
            System.out.print(", ");
            System.out.print(candidate.getPostalCode());
            System.out.print(", ");
            System.out.println(candidate.getCountryISO3());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy