Getting target IDs from promotions related to an order item I have a awful code with a big cyclomatic complexity. I have tried different variants, but haven't had good result. Please, help me to refactor this code:

public Set&lt;String&gt; getTargetIdsFromPromotion(String itemToRefundId, RepositoryItem orderItem) {
    Set&lt;String&gt; result = new HashSet&lt;String&gt;();
    List&lt;RepositoryItem&gt; relationships = getRelationships(orderItem);
    for (RepositoryItem relationship : relationships) {
        if (isValidShippingType(relationship)) {
            List&lt;RepositoryItem&gt; adjustments = getAdjustments(relationship);
            for (RepositoryItem adjustment : adjustments) {
                RepositoryItem promotion = getPromotion(adjustment);
                if (promotion != null){
                    Set&lt;String&gt; targetIds = getTargetIdsByQualifier(itemToRefundId, promotion);
                    if (!targetIds.isEmpty()) {
                        return targetIds;
                    }
                }
            }
        }
    }
    return new HashSet&lt;String&gt;();
}
Use the java 8 stream API:

public Set&lt;String&gt; getTargetIdsFromPromotion(String itemToRefundId, RepositoryItem orderItem) {
    return getRelationships(orderItem).stream()
            .filter(this::isValidShippingType)
            .map(this::getAdjustments)
            .flatMap(Collection::stream)
            .map(this::getPromotion)
            .filter(Objects::nonNull)
            .map(p -&gt; getTargetIdsByQualifier(itemToRefundId, p))
            .filter(s -&gt; !s.isEmpty())
            .findFirst()
            .orElseGet(Collections::emptySet);
}