Java: Send A Letter With SendLetter()

Download our Java samples from this page.
Find this sample in directory /test/com/postalmethods/client

This sample demonstrates how to send a letter through PostalMethods using the Address Inside method.

package com.postalmethods.client;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import com.postalmethods.client.api.SendLetterResponse;
 * Integration test that calls the SendLetter web method.
 * <p>
 * For details about PostalMethods.SendLetter see 
 * <a href="">the PostalMethods.SendLetter reference</a>
public class SendLetterTest {
    private PostalMethodsClient client;
    public void setUp() {
        client = new PostalMethodsClientFactory().build();
    public void testSendLetter() {
        System.out.println("Making call to SendLetter...");
        SendLetterResponse response = client.sendLetter("Sending test letter via JUnit integration test.", TestConstants.SAMPLE_LETTER_FILENAME);
        System.out.println("Service call completed:\n" + response.getResult().toString());
        int code = response.getResult().getCode();
        assertTrue(code > 0);
        System.out.println("New letter id is: " + code);