Java: Get The Status Of Multiple Letters with GetLetterStatusV2_Multiple()

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

package com.postalmethods.client;
 
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
 
import java.util.ArrayList;
import java.util.List;
 
import org.junit.Before;
import org.junit.Test;
 
import com.postalmethods.client.api.GetLetterStatusV2MultipleResponse;
import com.postalmethods.client.api.SendLetterV2Response;
import com.postalmethods.client.model.LetterStatus;
 
public class GetLetterStatusV2MultipleTest {
 
    private PostalMethodsClient client;
    private int letterId1, letterId2;
 
    @Before
    public void setUp() {
 
        client = new PostalMethodsClientFactory().build();
 
        // Send a sample letter so we have a letterId to check status on.
        SendLetterV2Response sendResponse = client.sendLetterV2("Junit test letter 1", TestConstants.SAMPLE_LETTER_FILENAME);
        int code = sendResponse.getResult().getCode();
        assertTrue(code > 0 );
        this.letterId1 = code;
 
        sendResponse = client.sendLetterV2("Junit test letter 2", TestConstants.SAMPLE_LETTER_FILENAME);
        code = sendResponse.getResult().getCode();
        assertTrue(code > 0 );
        this.letterId2 = code;
 
        try {
            Thread.sleep(6000);  // GetLetterStatus calls should be called no more than once every six seconds.
        } catch(Exception e) {}
    }
 
    @Test
    public void testGetLetterStatus() {
 
        List<Integer> letterIds = new ArrayList<Integer>(2);
        letterIds.add(letterId1);
        letterIds.add(letterId2);
 
        System.out.println("Making call to GetLetterStatusV2Multiple...");
        GetLetterStatusV2MultipleResponse response = client.getLetterStatusV2Multiple(letterIds);
        System.out.println("Service call completed:\n" + response.getResult().toString());
        int code = response.getResult().getCode();
        assertEquals(-3000, code); // success
 
        System.out.println("GetLetterStatusV2Multiple succeeded with code: " + response.getResult().toString());
 
        List<LetterStatus> letterStatusList = response.getLeterStatusList();
        assertEquals(2,letterStatusList.size());
 
        System.out.println(letterStatusList.get(0));
        System.out.println(letterStatusList.get(1));
    }
}