The key signature in this score contains two sharps (F# and C#). Two sharps correspond to either D major or its relative minor, B minor.
To distinguish between the two, examine the melodic content and the final note. The melody centres around D, uses notes from the D major scale, and concludes on D. These are strong indicators that the tonal centre is D rather than B.
Since the key signature has two sharps and the melodic evidence points to D as the tonic, the melody is in the key of D major.